package com.dg.lecheng.manager.controller;

import com.dg.lecheng.api.user.model.InfoUserRole;
import com.dg.lecheng.api.user.service.InfoUserRoleService;
import com.dg.lecheng.base.core.model.BaseResult;
import com.dg.lecheng.base.core.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * Created by Administrator on 2017/10/22 0022.
 */
@Api(value = "InfoUserRoleController" ,description = "用户角色Controller")
@Controller
@RequestMapping("/infoUserRole")
public class InfoUserRoleController extends BaseController{

    @Autowired
    private InfoUserRoleService infoUserRoleService;

    @ApiOperation("获取用户角色")
    @RequestMapping(value = "/getRoleByUserId/{userId}" ,method = RequestMethod.GET)
    @ResponseBody
    public Object addAuthForRole(@PathVariable int userId){
        List<InfoUserRole> lists = infoUserRoleService.getByUserId(userId);

        if(lists == null || lists.size() == 0){
            return BaseResult.fail(null);
        }
        return BaseResult.success(lists.get(0));
    }

}
